
import { ipcService } from '@renderer/services/ipcService';
import axios, { AxiosInstance } from 'axios'
import {ElMessage} from "element-plus";
import qs from 'qs';


const service: AxiosInstance = axios.create({
	baseURL: '',
	timeout: 50000,
	headers: { 'Content-Type': 'application/json' },
	paramsSerializer: {
		serialize(params) {
			return qs.stringify(params, { allowDots: true });
		},
	},
});



//响应拦截器根据后端状态码重定向或者提示
service.interceptors.response.use(
    response =>{
        return response
    },
    error=>{
        if(error.response){
            if(error.response.data) ElMessage.error(error.response.data)
            else ElMessage.error(error.response.statusText)
            ipcService.log.error(JSON.stringify(error.response))
        }
        else{
            ElMessage.error(error)
        }
    }
)

export default service;


